from django.test import TestCase

# Create your tests here.


def deduplicate_students(student_list, field):
    seen = set()
    unique_students = []

    for student in student_list:
        # 通过字段值构建唯一标识
        identifier = tuple(student[f] for f in field)

        # 如果标识未在已看到的集合中，则将学生信息添加到结果列表中并将标识添加到已看到的集合中
        if identifier not in seen:
            unique_students.append(student)
            seen.add(identifier)

    return unique_students




if __name__ == '__main__':
    students = [
        {'ID': 1, 'Name': 'Alice', 'Age': 20, 'Class': 'A', 'Teacher': 'Mr. Smith'},
        {'ID': 2, 'Name': 'Bob', 'Age': 21, 'Class': 'B', 'Teacher': 'Ms. Johnson'},
        {'ID': 1, 'Name': 'Alice', 'Age': 20, 'Class': 'A', 'Teacher': 'Mr. Brown'},
        {'ID': 3, 'Name': 'Charlie', 'Age': 19, 'Class': 'C', 'Teacher': 'Mrs. Davis'},
        {'ID': 2, 'Name': 'Bob', 'Age': 21, 'Class': 'B', 'Teacher': 'Ms. Thompson'}
    ]

    # 根据ID和Name去重
    unique_students = deduplicate_students(students, ['ID', 'Name'])
    print(unique_students)
